/* 
 * File:   main.cc
 * Author: iamani
 *
 * Created on February 16, 2012, 11:33 AM
 */

#include <cstdlib>
#include <iostream>
#include <string.h>

#include "../include/contest_interface.h"
#include "../include/Iterator.h"
#include "../include/util.h"

using namespace std;

Block* CreateBlock (const char* val) {
  Block* block = new Block;
  block->data = (void*) val;
  block->size = strlen(val);
  return block;
}

Record* CreateRecord (const int32_t k_1, const char* k_3, const char* payload) {
  Attribute** a = new Attribute*[2];
  a[0] = new Attribute;
  a[1] = new Attribute;

  a[0]->type = kShort;
  a[1]->type = kVarchar;

  a[0]->short_value = k_1;
  strcpy(a[1]->char_value, k_3);

  Record* record = new Record;
  record->key.value = a;
  record->key.attribute_count = 2;
  record->payload = *CreateBlock(payload);
  return record;
}

int main (int argc, char** argv) {

  Record *r1 = CreateRecord(1988, "Amani", "payload");
  printValue(r1);
  Record *r2 = CreateRecord(1987, "Flavia", "payload");
  printValue(r2);
  Record *r3 = CreateRecord(1988, "Basmah", "payload");
  printValue(r3);
  Record *r4 = CreateRecord(1986, "Sheikha", "payload");
  printValue(r4);
  Record *r5 = CreateRecord(1989, "Mohammad", "payload");
  printValue(r5);

  Iterator * myList = new Iterator(r1, NULL, r1->key, r1->key);

  myList->insert(r2);
  myList->insert(r3);
  myList->insert(r4);
  myList->insert(r5);

  int i = 0;
  do {
    std::cout << ++i << ": ";
    printValue(myList->value());
  } while (myList->next());

  myList->~Iterator();

  return 0;
}

